package com.gcu.common.web.exception;

import com.gcu.common.base.result.SysResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ system:Mac
 * @ author:lin tingfeng
 * @ data:2023/9/20 14:42
 * @ package_name:com.gcu.common.web.exception
 * @ project_name:SpringCloud-Oauth2
 * @ desc: 全局异常处理
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ResponseStatus(HttpStatus.OK)
    @ExceptionHandler(IllegalArgumentException.class)
    public <T> SysResult<T> handleIllegalArgumentException(IllegalArgumentException exception) {
        log.error("非法参数异常，异常原因：{}", exception.getMessage(), exception);
        return SysResult.failed(exception.getMessage());
    }

}
